import { ref, reactive } from 'vue';
// import type { FormRules } from 'element-plus'
 
export const isforewarning = ref(false);
export const isenable = ref(false);
export const evaluateIsenable = ref(false);
const responseSectionStart = ref();
const responseSectionEnd = ref();
const processingSectionStart = ref();
const processingSectionEnd = ref();
const ultimateSectionStart = ref();
const ultimateSectionEnd = ref();
export const eventInfoOptionsRules = reactive({
	exigenceLevel: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					callback();
				} else {
					callback(new Error('请选择紧急程度'));
				}
			},
		},
	],
	result: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					if (value.length >= 1 && value.length < 201) {
						if (value.includes(' ')) {
							value = value.replace(/\s/g, '');
							if(!value){
								callback(new Error('后果/影响必填'));
							}
							callback();
						} else {
							callback();
						}
					} else {
						callback(new Error('长度为1-200个字符'));
					}
				} else {
					callback(new Error('后果/影响必填'));
				}
			},
		},
	],
	eventLevel: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					callback();
				} else {
					callback(new Error('事件等级必选'));
				}
			},
		},
	],
	eventTypeNum: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value) {
					if (value.includes(' ')) {
						value = value.replace(/\s/g, '');
						if (value.length > 0 && value.length < 51) {
							callback();
						} else {
							callback(new Error('长度为1-50个字符'));
						}
					} else {
						if (value.length > 0 && value.length < 51) {
							callback();
						} else {
							callback(new Error('长度为1-50个字符'));
						}
					}
				} else {
					callback();
				}
			},
		},
	],
	processGroup: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					callback();
				} else {
					callback(new Error('区域处置单位必选'));
				}
			},
		},
	],
	enable: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					callback();
				} else {
					callback(new Error('状态单选按钮必选'));
				}
			},
		},
	],
});

export const eventForewarningOptionsRules = reactive({
	isForewarning: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					if (value === '1') {
						isforewarning.value = true;
						callback();
					}
					if (value === '0') {
						isforewarning.value = false;
						callback();
					}
				} else {
					callback(new Error('是否预警必选'));
				}
			},
		},
	],
	personThreshold: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value<=0) {
						callback(new Error('请输入正整数'));
					} if (!value) {
						callback()
					} else {
						if (value%1===0) {
							callback();
						} else {
							callback(new Error('请输入正整数'));
						}
					}
			},
		},
	],
	forewarningContent: [
		{
			required: isforewarning.value === true ? true : false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value && value!='undefined') {
						if (value.includes(' ')) {
							value = value.replace(/\s/g, '');
							if (value.length > 0 && value.length < 201) {
								callback();
							} else {
								callback(new Error('长度为1-200个字符'));
							}
						} else {
							if (value.length > 0 && value.length < 201) {
								callback();
							} else {
								callback(new Error('长度为1-200个字符'));
							}
						}
					} else {
						if (isforewarning.value === true) {
							callback(new Error('预警内容必填'));
						}
						callback()
					}
				
			},
		},
	],
});

export const eventIntoAccidentOptionsRules = reactive({
	isenable: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {
					if (value === '1') {
						isenable.value = true;
						callback();
					}
					if (value === '0') {
						isenable.value = false;
						callback();
					}
				} else {
					callback(new Error('是否启用必选'));
				}
			},
		},
	],
	intoPersonThreshold: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value<=0) {
					callback(new Error('请输入正整数'));
				} if (!value) {
					callback()
				} else {
					if (value%1===0) {
						callback();
					} else {
						callback(new Error('请输入正整数'));
					}
				}
			},
		},
	],
	intoForewarningContent: [
		{
			required: isenable.value === true ? true : false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value  && value!='undefined') {
						if (value.includes(' ')) {
							value = value.replace(/\s/g, '');
							if (value.length > 0 && value.length < 201) {
								callback();
							} else {
								callback(new Error('长度为1-200个字符'));
							}
						} else {
							if (value.length > 0 && value.length < 201) {
								callback();
							} else {
								callback(new Error('长度为1-200个字符'));
							}
						}
					} else {
						if (isenable.value === true) {
							callback(new Error('预警内容必填'));
						}
						callback()
					}
				
			},
		},
	],
});

export const eventEvaluateOptionsRules = reactive({
	evaluateIsenable: [
		{
			required: true,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value && value!='undefined') {

					if (value === '1') {
						evaluateIsenable.value = true;
						callback();
					}
					if (value === '0') {
						evaluateIsenable.value = false;
						callback();
					}
				} else {

					callback(new Error('是否启用必选'));
				}
			},
		},
	],
	responseTime: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value) {
						value = value.replace(/\s/g, '');
						const result = /^\d+$/.test(value);
						if (!result) {
							callback(new Error('请输入正整数'));
						} else {
							if (value > 0 && value%1===0) {
								callback();
							} else {
								callback(new Error('请输入正整数'));
							}
						}
					} else {
						callback();
					}
			},
		},
	],
	responseWeight: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value) {
						value = value.replace(/\s/g, '');
						const result = /^\d+(\.\d+)?$/.test(value);
						if (!result) {
							callback(new Error('请输入正数'));
						} else {
							callback()
						}
					} else {
						callback();
					}
			},
		},
	],
	responseSectionStart: [
		{
			required: responseSectionEnd.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				responseSectionStart.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))

						if (!responseSectionEnd.value) callback();

						if (value >= responseSectionEnd.value) callback(new Error('不能比结束区间大'));

						callback();
					} else {
						if (responseSectionEnd.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}
				
			},
		},
	],
	responseSectionEnd: [
		{
			required: responseSectionStart.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				responseSectionEnd.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))
						if (!responseSectionStart.value) callback();
						if (value <= responseSectionStart.value) {
							callback(new Error('不能比起始区间小'));
						}
						callback();
					} else {
						if (responseSectionStart.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}
				
			},
		},
	],
	processing: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value) {
						if (value.includes(' ')) {
							value = value.replace(/\s/g, '');
							callback();
						} else {
							callback();
						}
					} else {
						callback();
					}
			},
		},
	],
	processingWeight: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value) {
					value = value.replace(/\s/g, '');
					const result = /^\d+(\.\d+)?$/.test(value);
					if (!result) {
						callback(new Error('请输入正数'));
					} else {
						callback()
					}
				} else {
					callback();
				}
			},
		},
	],
	processingSectionStart: [
		{
			required: processingSectionEnd.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				processingSectionStart.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))
						if (!processingSectionEnd.value) callback();
						if (value >= processingSectionEnd.value) {
							callback(new Error('不能比结束区间大'));
						}
						callback();
					} else {
						if (processingSectionEnd.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}
			},
		},
	],
	processingSectionEnd: [
		{
			required: processingSectionStart.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				processingSectionEnd.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))
						if (!processingSectionStart.value) callback();
						if (value <= processingSectionStart.value) {
							callback(new Error('不能比起始区间小'));
						}
						callback();
					} else {
						if (processingSectionStart.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}
			},
		},
	],
	ultimate: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
					if (value) {
						if (value.includes(' ')) {
							value = value.replace(/\s/g, '');
							callback();
						} else {
							callback();
						}
					} else {
						callback();
					}
			},
		},
	],
	ultimateWeight: [
		{
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				if (value) {
					value = value.replace(/\s/g, '');
					const result = /^\d+(\.\d+)?$/.test(value);
					if (!result) {
						callback(new Error('请输入正数'));
					} else {
						callback()
					}
				} else {
					callback();
				}
			},
		},
	],
	ultimateSectionStart: [
		{
			required: ultimateSectionEnd.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				ultimateSectionStart.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))
						if (!ultimateSectionEnd.value) callback();
						if (value >= ultimateSectionEnd.value) {
							callback(new Error('不能比结束区间大'));
						}
						callback();
					} else {
						if (ultimateSectionEnd.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}
			},
		},
	],
	ultimateSectionEnd: [
		{
			required: ultimateSectionStart.value? true:false,
			trigger: 'change',
			validator: (rule: any, value: any, callback: any) => {
				ultimateSectionEnd.value = value;
					if (value) {
						if (value<0) callback(new Error('不能为负数'))
						if (!ultimateSectionStart.value) callback();
						if (value <= ultimateSectionStart.value) {
							callback(new Error('不能比起始区间小'));
						}
						callback();
					} else {
						if (ultimateSectionStart.value) {
							callback(new Error('得分区间必填'));
						}
						callback()
					}

			},
		},
	],
});
